# import os
# import django
#
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.base")
# django.setup()  # 这里不能加这几句，否则admin报错无法从models中导入类

from django.contrib import admin
from django.apps import apps, AppConfig


class ListAdminMixin(object):
    def __init__(self, model, admin_site):
        self.list_display = [field.name for field in model._meta.fields]
        super(ListAdminMixin, self).__init__(model, admin_site)


class UniversalManagerApp(AppConfig):
    """
    应用配置在 所有应用的Admin 都加载完后执行
    所有应用加载完后最后才会加载这个应用
    """
    name = 'recruitment'

    # ready 方法是在这个应用加载完之后执行的
    def ready(self):
        # # print(apps.get_app_config())
        # models = apps.get_app_config('running').get_models()
        # for model in models:
        #     admin_class = type('AdminClass', (ListAdminMixin, admin.ModelAdmin), {})
        #     try:
        #         admin.site.register(model, admin_class)
        #     except Exception as e:
        #         pass
        pass